#include<iostream>
#include"vector.h"

using namespace math;

template<class Array>
void output(const Array &a)
{
    std::cout << "size      :" << a.size() << std::endl;
    std::cout << "max_size  :" << a.max_size() << std::endl;
	std::cout << "empty     :" << std::boolalpha << a.empty() << std::endl;
    std::cout << "elements  :" ;
	
	for(auto i = a.rbegin(); i != a.rend(); ++i)
		std::cout << *i << " ";
/*
    for(auto &i : a)
        std::cout << i << " ";
		*/
    std::cout <<  "\n\n";
}

//test of vector.
int main()
{
    typedef vector<double> Array;

    //default constructor
	std::cout << "1. default constructor:\n";
    Array a1;
    output(a1);

    // non-init constructor
	std::cout << "2. non-init constructor:\n";
    Array a2(10);
    output(a2);

    // init-constructor
	std::cout << "3. init-constructor:\n";
    Array a3(14,1.6);
    output(a3);

    //copy constructor
	std::cout << "4. copy-constructor:\n";
    Array a4(a3);
    output(a4);

    //range constructor
	std::cout << "5. range-constructor:\n";
    int a[] = {1,2,3,4,5};
    Array a5(a + 0, a+ 3);
    output(a5);

    //assignment
	std::cout << "6. assignment:\n";
    a2 = a3;
    output(a2);

    //move assignment
	std::cout << "7. move assignment:\n";
    a2 =(Array(20,1));
    output(a2);

    //swap
	std::cout << "8. swap:\n";
    std::cout << "before swap" << std::endl;
    output(a2);
    output(a3);
    std::cout << "std::swap" << std::endl;
    std:swap(a2,a3);
    output(a2);
    output(a3);
    std::cout << "member swap:" << std::endl;
    a2.swap(a3);
    output(a2);
    output(a3);
    std::cout << "friend swap:" << std::endl;
    swap(a2, a3);
    output(a2);
    output(a3);

    //resize
	std::cout << "9. resize:\n";
    std::cout << "before resize" << std::endl;
    output(a2);
    std::cout << "become smaller" << std::endl;
    a2.resize(5,true);
    output(a2);
    std::cout << "become larger:"<< std::endl;
    a2.resize(40);
    output(a2);

	//converse
	std::cout << "10. converse:\n";
	Array a6 = vector<int>(12,3);
	output(a6);

	std::cout << "11. += -= *= /=:\n";
	output(a6 += 2);
	output(a6 -= 2);
	output(a6 += 2);
	output(a6 -= 2);
	output(a6 *= 2);
	output(a6 /= 2);
	output(a6 += vector<int>(12, 10));
	output(a6 -= vector<int>(12, 10));
	output(a6 *= vector<int>(12, 10));
	output(a6 /= vector<int>(12, 10));

	std::cout << "12. + - * /:\n";
	output(a6 + a6);
	output(a6 + a6 + a6);
	output(a6 + (a6 + a6));
	output((a6 + a6) + (a6 + a6));

	output(a6 - a6);
	output(a6 - a6 - a6);
	output(a6 - (a6 - a6));
	output((a6 - a6) - (a6 - a6));

	output(a6 * a6);
	output(a6 * a6 * a6);
	output(a6 * (a6 * a6));
	output((a6 * a6) * (a6 * a6));

	output(a6 / a6);
	output(a6 / a6 / a6);
	output(a6 / (a6 / a6));
	output((a6 / a6) / (a6 / a6));
}

